package com.managedBean.user;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

import com.controller.merchant.OrderController;
import com.dto.merchant.OrderDTO;
import com.utils.ApplicationUtils;

@ViewScoped
@ManagedBean(name = "myChartsManagedBean")
public class MyChartsManagedBean implements Serializable {

	private static final long serialVersionUID = 4219111797431239124L;
	@ManagedProperty(value = "#{orderController}")
	private OrderController orderController;
	private List<OrderDTO> orderList;
	private CartesianChartModel ordersByDateModel;

	@PostConstruct
	public void init() {
		orderList = orderController.getOrderList();
		ordersByDateModel = new CartesianChartModel();
		ChartSeries ordersChartSeries = new ChartSeries();
		ordersChartSeries.setLabel("Orders By Date");
		for (OrderDTO dto : orderList) {
			ordersChartSeries.set(
					ApplicationUtils.dateToString(dto.getOrderDate()),
					Double.parseDouble(dto.getAmount()));
		}
		ordersByDateModel.addSeries(ordersChartSeries);
	}

	/**
	 * @return the orderController
	 */
	public OrderController getOrderController() {
		return orderController;
	}

	/**
	 * @param orderController
	 *            the orderController to set
	 */
	public void setOrderController(OrderController orderController) {
		this.orderController = orderController;
	}

	/**
	 * @return the orderList
	 */
	public List<OrderDTO> getOrderList() {
		return orderList;
	}

	/**
	 * @param orderList
	 *            the orderList to set
	 */
	public void setOrderList(List<OrderDTO> orderList) {
		this.orderList = orderList;
	}

	/**
	 * @return the ordersByDateModel
	 */
	public CartesianChartModel getOrdersByDateModel() {
		return ordersByDateModel;
	}

	/**
	 * @param ordersByDateModel
	 *            the ordersByDateModel to set
	 */
	public void setOrdersByDateModel(CartesianChartModel ordersByDateModel) {
		this.ordersByDateModel = ordersByDateModel;
	}

}
